package com.xujl.mvcbind.ui.db.control;

import android.os.Bundle;
import android.view.View;

import com.xujl.fastlib.base.BaseFragment;
import com.xujl.mvcbind.R;
import com.xujl.mvcbind.bean.OverTimeEntity;
import com.xujl.mvcbind.consts.BundleKey;
import com.xujl.mvcbind.exception.ParamsException;
import com.xujl.mvcbind.ui.db.model.AddOverTimeFragmentModel;
import com.xujl.mvcbind.ui.db.view.AddOverTimeFragmentView;

/**
 * <pre>
 *     author : xujl
 *     e-mail : 597355068@qq.com
 *     time   : 2019/08/20
 *     desc   : 添加加班记录
 *     version: 1.0
 * </pre>
 */

public class AddOverTimeFragmentControl extends BaseFragment<AddOverTimeFragmentModel, AddOverTimeFragmentView> {
    public static AddOverTimeFragmentControl newInstance (OverTimeEntity entity) {
        Bundle args = new Bundle();
        AddOverTimeFragmentControl fragment = new AddOverTimeFragmentControl();
        args.putSerializable(BundleKey.DATA, entity);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void init (Bundle savedInstanceState) {
        mModel.saveBundle(getArguments());
        mView.setData(mModel.getEntity());
        mView.setDatePickerCallback(mModel);
    }

    @Override
    public void onClick (View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.btn_confirm:
                try {
                    mModel.saveData();
                    mView.toast("保存成功");
                    pop();
                } catch (ParamsException e) {
                    mView.toast(e.getMessage());
                }
                break;
            case R.id.btn_1:
                mModel.getEntity().setDuration("1");
                break;
            case R.id.btn_8:
                mModel.getEntity().setDuration("8");
                break;
            case R.id.btn_add:
                mModel.durationAdd();
                break;
            case R.id.btn_sub:
                mModel.durationSub();
                break;
            case R.id.tv_date:
               mView.showDatePicker();
                break;
            default:

                break;

        }
    }
}
